<?php namespace xlx\lib; 
class CircleQueue implements \IteratorAggregate  {

    public $index = 0;
    public $items=null;
    public function __construct($arr=[]){
        $this->items = $arr;
    }
    public function push($item):int{
        $this->items[]=$item;
        return count($this->items)-1;
    }  
    public function splice($k,$l=1){ 
        array_splice($this->items,$k,$l); 
    }
    public function getIterator(){ 
        /*/
        for ($i=0,$len=count($this->items); $i < $len; $i++) 
            yield $i =>$this->items[$i];
        /*/
        $len = count($this->items);      //环形队列 
        $v = $len/2 < $this->index?1:-1; //往靠近坐标0的方向查找 
        for ($i=0; $i < $len; $i++) {    
            $this->index = ($len+$this->index) % $len;  
            yield $this->index => $this->items[ $this->index ];
            $this->index += $v; 
        }  
    }
}